'''
Created on 2020年3月3日

@author: Administrator
'''
from orm.model import Area
from view.baseview import BaseView

class AreaView(BaseView):
    def __init__(self):
        pass
    
    def getAreas(self,):
        """取得区域列表"""
        result=[]
        rows = Area.select()
        for row in rows:
            result.append(row.areaname)
        return super().resultSet(200, "区域列表取得成功", result)

    def addArea(self,name):
        """添加区域"""
        result=[]
        rows = Area.select().where(Area.areaname == name)
        if rows:
            return super().resultSet(410, "区域名称已存在", result)
        else:
            Area.create(
                areaname = name
            )
        return super().resultSet(200, "区域列表取得成功", result)


if __name__ == '__main__':
    tv = AreaView()
    res = tv.getAreas()
    print(res)
    res = tv.addArea("苏州")
    print(res)
